package com.coldlz.mmp.proxy.handlerclient;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.websocketx.WebSocket13FrameDecoder;
import io.netty.handler.codec.http.websocketx.WebSocketDecoderConfig;

import java.util.List;

public class WebSocketClientFrameDecoder extends WebSocket13FrameDecoder {
    public WebSocketClientFrameDecoder(boolean expectMaskedFrames, boolean allowExtensions, int maxFramePayloadLength) {
        super(expectMaskedFrames, allowExtensions, maxFramePayloadLength);
    }

    public WebSocketClientFrameDecoder(boolean expectMaskedFrames, boolean allowExtensions, int maxFramePayloadLength, boolean allowMaskMismatch) {
        super(expectMaskedFrames, allowExtensions, maxFramePayloadLength, allowMaskMismatch);
    }

    public WebSocketClientFrameDecoder(WebSocketDecoderConfig decoderConfig) {
        super(decoderConfig);
    }

    @Override
    public void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        int len = in.readableBytes();
        byte[] bytes = new byte[len];
        int startIndex = in.readerIndex();
        in.readBytes(bytes);
        String c = new String(bytes);
        in.readerIndex(startIndex);
        super.decode(ctx, in, out);
    }
}
